<!DOCTYPE html>
<html>

<head>
	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<meta name="theme-color" content="#33474d">
	<title>vim设置自动缩进 | 失落的乐章</title>
	<link rel="stylesheet" href="/css/style.css" />
	
      <link rel="alternate" href="/atom.xml" title="失落的乐章" type="application/atom+xml">
    
</head>

<body>

	<header class="header">
		<nav class="header__nav">
			
				<a href="/archives" class="header__link">Archive</a>
			
				<a href="/tags" class="header__link">Tags</a>
			
				<a href="/atom.xml" class="header__link">RSS</a>
			
		</nav>
		<h1 class="header__title"><a href="/">失落的乐章</a></h1>
		<h2 class="header__subtitle">技术面前，永远都是学生。</h2>
	</header>

	<main>
		<article>
	
		<h1>vim设置自动缩进</h1>
	
	<div class="article__infos">
		<span class="article__date">2017-10-12</span><br />
		
		
			<span class="article__tags">
			  	<a class="article__tag-link" href="/tags/Linux/">Linux</a>
			</span>
		
	</div>

	

	
		<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;centos系统，修改vim的配置文件 /etc/vimrc</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;添加如下内容：<br>1)  打开 vimrc ，添加以下语句来使得语法高亮显示：<br>syntax on<br>2)  如果此时语法还是没有高亮显示，那么在 /etc 目录下的 profile 文件中添加以下语句：<br>export TERM=xterm-color<br>3) 解决方向键和退格键失效的问题（采用非兼容模式）<br>set nocompatible<br>set backspace=2<br>4) 设置 Windows 风格的 C/C++ 自动缩进（添加以下 set 语句到 vimrc 中）</p>
<ul>
<li>设置（软）制表符宽度为 4 ：<br>set tabstop=4<br>set softtabstop=4</li>
<li>设置缩进的空格数为 4<br>set shiftwidth=4</li>
<li>设置自动缩进 ：即每行的缩进值与上一行相等；使用  noautoindent  取消设置：<br>set autoindent</li>
<li>设置 使用  C/C++  语言的自动缩进方式：<br>set cindent</li>
<li>设置 C/C++ 语言的具体缩进方式 ：<br>set cinoptions={0,1s,t0,n-2,p2s,(03s,=.5s,&gt;1s,=1s,:1s</li>
<li>如果想在左侧显示文本的行号，可以用以下语句：<br>set nu</li>
<li>最后，如果没有下列语句，就加上吧:</li>
</ul>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">if</span> &amp;term==<span class="string">"xterm"</span></div><div class="line"><span class="built_in">set</span> t_Co=8</div><div class="line">             <span class="built_in">set</span> t_Sb=^[[4%dm</div><div class="line"><span class="built_in">set</span> t_Sf=^[[3%dm</div><div class="line">endif</div></pre></td></tr></table></figure>
	

	
		<span class="different-posts"><a href="/2017/10/12/1. Linux 基础/32. vim设置设置自动缩进/" onclick="window.history.go(-1); return false;">⬅️ Go back </a></span>

	

</article>

	</main>

	<footer class="footer">
	<div class="footer-content">
		
	      <div class="footer__element">
	<p>Hi there, <br />welcome to my Blog glad you found it. Have a look around, will you?</p>
</div>

	    
	      <div class="footer__element">
	<h5>Check out</h5>
	<ul class="footer-links">
		<li class="footer-links__link"><a href="/archives">Archive</a></li>
		
		  <li class="footer-links__link"><a href="/atom.xml">RSS</a></li>
	    
		<li class="footer-links__link"><a href="/about">about page</a></li>
		<li class="footer-links__link"><a href="/tags">Tags</a></li>
		<li class="footer-links__link"><a href="/categories">Categories</a></li>
	</ul>
</div>

	    

		<div class="footer-credit">
			<span>© 2017 失落的乐章 | Powered by <a href="https://hexo.io/">Hexo</a> | Theme <a href="https://github.com/HoverBaum/meilidu-hexo">MeiliDu</a></span>
		</div>

	</div>


</footer>



</body>

</html>
